package cn.retalsystem.controller;

import cn.retalsystem.service.RentalService;
import cn.retalsystem.vo.ZulinVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * @Author: Xsan
 * @Date: 2019/11/1 15:10
 * @Version 1.0
 * @描述：
 */
@Controller
@RequestMapping("/rental")
public class RentalController {
    @Autowired//注入service
    RentalService rentalService;


  //初始化页面，
    @RequestMapping("/init")
    public String init(Model model,String fjname,Integer fjzt){
        System.out.println(fjname);


        int h = rentalService.hcconut(fjname,fjzt);
        //数据总数传入
        model.addAttribute("count",h);
        model.addAttribute("fjname",fjname);
        model.addAttribute("fjzt",fjzt);
        return "rental_management";

    }

    /**
     * 分页查询信息
     * @param page 当前页
     * @param limit 单页楼栋信息数量
     * @return
     */

    @RequestMapping("/table")
    @ResponseBody
    public List sjjh(Integer page, Integer limit,String fjname,Integer fjzt) {

        return rentalService.huoQu(page, limit, fjname, fjzt);
    }

    /**
     * 删除数据
     *  fjid 房间id
     * @return
     */
    @RequestMapping("/del")
    @ResponseBody
        public int  del(int []  id){
        System.out.println(id);
        for (int i : id) {
            System.out.println("遍历"+i);
            rentalService.deltableinfo(i);


        }

       return 4;


    }

    /**
     * 出租状态修改
     *  fjid 房间id
     * @return
     */
    @RequestMapping("/cz")
    @ResponseBody
    public int  updzt(int [] id) {

        for (int i : id) {
            int   result = rentalService.czZt(i);
            return result;
        }

          return 4;
    }
    /**
     * 退租状态修改
     *  fjid 房间id
     * @return
     */

    @RequestMapping("/tz")
    @ResponseBody
    public int  uptz(int [] id) {

        for (int i : id) {
            int   result = rentalService.tzZt(i);
            return result;
        }
        return 4;
    }





}
